package com.bb.blog.code.threading.example;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.RecursiveTask;
import java.util.stream.LongStream;

public class ForkJoinExample {
    public static void main(String[] args) {
        long[] numbers = LongStream.rangeClosed(1, 1000000).toArray();

        ExecutorService forkJoinPool = Executors.newWorkStealingPool();
//        forkJoinPool.execute();
        SumTask sumTask = new SumTask(1, 2, numbers);
        sumTask.fork();
        Long join = sumTask.join();
        System.out.println(join);
    }


    static class SumTask extends RecursiveTask<Long> {
        private long[] numbers;
        private int from;
        private int to;

        SumTask(int from, int to, long[] numbers) {
            this.from = from;
            this.to = to;
            this.numbers = numbers;
        }

        @Override
        protected Long compute() {

            return 10l;
        }
    }
}
